package atencion_de_emergencia.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import utilitarios.MiConexion;
import atencion_de_emergencia.bean.ColorDTO;
import atencion_de_emergencia.interfaces.ColorDAO;

public class MySqlColorDAO implements ColorDAO{

	@Override
	public List<ColorDTO> listadoColor() throws Exception {
		List<ColorDTO> color = new ArrayList<ColorDTO>() ;
		Connection cn = MiConexion.obtenerConexion();
		
		try {

			String sql	=	"select distinct Cod_Color,Desc_Color from color";
			System.out.println("SENTENCIA SQL : " + sql);
			
			Statement pstm = cn.createStatement();
			ResultSet rs = pstm.executeQuery(sql);

			while (rs.next()) {
						
				ColorDTO objColor = new ColorDTO();
			
				objColor.setStrCod_Color(rs.getString(1));
				objColor.setStrDesc_Color(rs.getString(2));
										
				color.add(objColor);
			}
			
			rs.close();
			pstm.close();
			
		} catch (SQLException e) {
			e.printStackTrace();
		} finally{
			cn.close();
		}

		return color;
	}

}
